define(
    function (require) {
        require('tpl!./form.tpl.html');

        var util = require('common/util');

        var BaseFormView = require('common/FormView');

        function FormView() {
            BaseFormView.apply(this, arguments);
        }

        FormView.prototype.template = 'foodShopForm';

        FormView.prototype.enterDocument = function() {
            BaseFormView.prototype.enterDocument.apply(this, arguments);
        };

        /**
         * 从表单中获取实体数据
         *
         * @return {Object}
         */
        FormView.prototype.getEntity = function () {
            var entity = BaseFormView.prototype.getEntity.apply(this, arguments);
           var flg =true;
           if($("#password").val().length<6){
               flg = false;
               alert("原始密码长度为6~10有效字符！");
           }else if($("#xpassword").val().length<6){
               flg = false;
               alert("新密码长度为6~10有效字符！");
           }else if($("#xnpassword").val().length<6){
               flg = false;
               alert("重复密码长度为6~10有效字符！");
           } else if($("#xpassword").val() !== $("#xnpassword").val()){
               flg = false;
                alert("原始密码与重复密码输入不一致！");
           }
           if(flg){
               $.ajax(
                   {
                       url: '/api/updateTicketShop',
                       data: {odpassword:$("#password").val(),xpassword:$("#xnpassword").val()},
                       type: 'get',
                       dataType: 'json',
                       contentType: "application/json",
                       success: function (data) {
                           if(data.code === 1){
                                alert(data.msg);
                               window.location.reload();
                           }else if(data.code === 0){
                               location.href='/main.html#/equipment/list';
                           }
                       }
                   }
               );
           }
        };

        require('er/util').inherits(FormView, BaseFormView);
        return FormView;
    }
);
